package com.bocloud.cmp.service.app.resource;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.bocloud.cmp.entity.app.resource.ApplicationSoftwareInfo;
import com.bocloud.cmp.interfaces.app.resource.ApplicationSoftwareInfoService;
import com.bocloud.common.model.BsmResult;
import com.bocloud.common.model.GridBean;
import com.bocloud.common.model.Param;
import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.GridHelper;
import com.google.common.collect.Maps;

@Service("applicationSoftwareInfoService")
public class ApplicationSoftwareInfoServiceImpl extends CommonServiceImpl implements ApplicationSoftwareInfoService {

	private static Logger logger = LoggerFactory.getLogger(ApplicationServiceImpl.class);
	
	@Override
	public boolean saveApplicationSoftwareInfo(ApplicationSoftwareInfo applicationSoftwareInfo) throws Exception {
		return applicationSoftwareInfoDao.saveApplicationSoftwareInfo(applicationSoftwareInfo);
	}

	@Override
	public boolean deleteApplicationSoftwareInfo(ApplicationSoftwareInfo applicationSoftwareInfo) throws Exception {
		return applicationSoftwareInfoDao.deleteApplicationSoftwareInfo(applicationSoftwareInfo);
	}

	@Override
	public boolean updateApplicationSoftwareInfo(ApplicationSoftwareInfo applicationSoftwareInfo) throws Exception {
		return applicationSoftwareInfoDao.updateApplicationSoftwareInfo(applicationSoftwareInfo);
	}

	@Override
	public ApplicationSoftwareInfo getByAppIdAndSoftwareId(Long appId, Long softwareId) throws Exception {
		return applicationSoftwareInfoDao.getByAppIdAndSoftwareId(appId, softwareId);
	}

	@Override
	public ApplicationSoftwareInfo get(Long id) throws Exception {
		return applicationSoftwareInfoDao.get(id);
	}

	@Override
	public List<ApplicationSoftwareInfo> getByAppId(Long appId) throws Exception {
		return applicationSoftwareInfoDao.getByAppId(appId);
	}
	
	@Override
	public BsmResult list(int page, int rows, List<Param> params, Map<String, String> sorter, Boolean simple) {
		GridBean gridBean;
		try {
			if (null == sorter) {
				sorter = Maps.newHashMap();
			}
			sorter.put("id", Common.ONE);
			int total = applicationSoftwareInfoDao.count(params);
			List<ApplicationSoftwareInfo> list = applicationSoftwareInfoDao.list(page, rows, params, sorter);
			gridBean = GridHelper.getBean(page, rows, total, list);
			return new BsmResult(true, gridBean, "查询成功");
		} catch (Exception e) {
			logger.error("list deployHistory failure:", e);
			return new BsmResult(false, "查询失败");
		}
	}

}
